
import java.awt.Color;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Makstanley
 */
public class JET_Wing_MyForm extends javax.swing.JFrame {

    /**
     * Creates new form JET_Wing_MyForm
     */
    
        Connection conn = null;
        PreparedStatement p = null;
        ResultSet rs = null;
        
        String[] colname = {"fName", "from", "destination", "price", "fCapacity","depatureTime","arrivalTime" };
        String [] searchOptions = {"fName","fFrom", "destination", "price",  "fCapacity","depatureTime","arrivalTime"};
        DefaultTableModel dm = new DefaultTableModel(colname, 7);
    
    
    
    public JET_Wing_MyForm() {
        initComponents();

        setVisible(true);
        getContentPane().setBackground(Color.BLACK);
        flightTable.setEnabled(false);
      
        flightTable.setModel(dm);
        dm.setColumnIdentifiers(colname);
        msgLabel.setText("Select either fName, destination, depatureTime or arrivalTime");
        
        
        for(int i=0; i<searchOptions.length;i++){       //add items to combobox
           searchCombo.addItem(searchOptions[i]);       
        }
        
        System.out.println("SQL Test");

        try {
            
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/jetwingdb?user=root&password=");
        } catch (Exception e) {
            System.out.println(e);
            System.exit(0);
        }

        System.out.println("Connection established");
    
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    
    
    //this method refreshes the table, that is displays everything in the db
   
    
    
 
    
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        SearchButtonFlight = new javax.swing.JButton();
        SearchFlightText = new javax.swing.JTextField();
        searchCombo = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        flightTable = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        SEARCHButtonReservation = new javax.swing.JButton();
        SEARCHButtonEmployee = new javax.swing.JButton();
        msgLabel = new javax.swing.JLabel();
        CLOSEButton = new javax.swing.JButton();

        jLabel1.setText("jLabel1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        SearchButtonFlight.setBackground(new java.awt.Color(0, 51, 204));
        SearchButtonFlight.setText("SEARCH");
        SearchButtonFlight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchButtonFlightActionPerformed(evt);
            }
        });

        SearchFlightText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchFlightTextActionPerformed(evt);
            }
        });

        searchCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchComboActionPerformed(evt);
            }
        });

        flightTable.setForeground(new java.awt.Color(0, 102, 102));
        flightTable.setModel(dm);
        jScrollPane1.setViewportView(flightTable);

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 1, 18)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(0, 102, 204));
        jLabel2.setText("JET-WING FLIGHT SEARCH PAGE");

        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("FLIGHT");

        SEARCHButtonReservation.setBackground(new java.awt.Color(0, 51, 204));
        SEARCHButtonReservation.setText("SEARCH USING RESERVATION");
        SEARCHButtonReservation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SEARCHButtonReservationActionPerformed(evt);
            }
        });

        SEARCHButtonEmployee.setBackground(new java.awt.Color(0, 51, 204));
        SEARCHButtonEmployee.setText("SEARCH USING  EMPLOYEE");
        SEARCHButtonEmployee.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SEARCHButtonEmployeeActionPerformed(evt);
            }
        });

        msgLabel.setText("jLabel6");

        CLOSEButton.setBackground(new java.awt.Color(0, 51, 204));
        CLOSEButton.setForeground(new java.awt.Color(0, 51, 51));
        CLOSEButton.setText("CLOSE");
        CLOSEButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CLOSEButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(layout.createSequentialGroup()
                                .add(jLabel3)
                                .add(18, 18, 18)
                                .add(searchCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(18, 18, 18)
                                .add(SearchFlightText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 158, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(18, 18, 18)
                                .add(SearchButtonFlight))
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                .add(org.jdesktop.layout.GroupLayout.TRAILING, SEARCHButtonEmployee, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.TRAILING, SEARCHButtonReservation, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .add(142, 142, 142))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(CLOSEButton)
                        .add(204, 204, 204))))
            .add(layout.createSequentialGroup()
                .add(62, 62, 62)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(msgLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 535, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(0, 61, Short.MAX_VALUE)))
                .addContainerGap())
            .add(layout.createSequentialGroup()
                .add(189, 189, 189)
                .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 307, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(19, 19, 19)
                .add(jLabel2)
                .add(45, 45, 45)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(searchCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(SearchFlightText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(SearchButtonFlight)
                    .add(jLabel3))
                .add(33, 33, 33)
                .add(SEARCHButtonReservation)
                .add(18, 18, 18)
                .add(SEARCHButtonEmployee)
                .add(35, 35, 35)
                .add(msgLabel)
                .add(18, 18, 18)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 158, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(CLOSEButton)
                .addContainerGap(40, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void SearchFlightTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchFlightTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SearchFlightTextActionPerformed

    private void SearchButtonFlightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchButtonFlightActionPerformed
        // TODO add your handling code here:
               
         
    }//GEN-LAST:event_SearchButtonFlightActionPerformed
    
  
   public JButton getCLOSEButton(){
       return  CLOSEButton;
    }
   
   
   
    public JButton getSEARCHButtonEmployee(){
       return  SEARCHButtonEmployee;
    }
    
    
  public JButton getSEARCHButtonReservation(){
       return  SEARCHButtonReservation;
    }   
    
    
     public JButton getSearchButtonFlight(){
       return  SearchButtonFlight;
    }  
    
    
      
public JTextField getSearchFlightText(){
       return  SearchFlightText;
    } 
    

public JComboBox getsearchCombo(){
       return  searchCombo;
    }


public JLabel getmsgLabel(){
       return  msgLabel;
    }



public JTable getflightTable(){
       return  flightTable;
    }


public DefaultTableModel getModel(){
return dm;
}  
     
       
    
    private void SEARCHButtonReservationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SEARCHButtonReservationActionPerformed
        // TODO add your handling code here: 
    }//GEN-LAST:event_SEARCHButtonReservationActionPerformed

    private void SEARCHButtonEmployeeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SEARCHButtonEmployeeActionPerformed
        // TODO add your handling code here:     
    }//GEN-LAST:event_SEARCHButtonEmployeeActionPerformed

    private void searchComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchComboActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchComboActionPerformed

    private void CLOSEButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CLOSEButtonActionPerformed
        // TODO add your handling code here:     
    }//GEN-LAST:event_CLOSEButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JET_Wing_MyForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JET_Wing_MyForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JET_Wing_MyForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JET_Wing_MyForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JET_Wing_MyForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CLOSEButton;
    private javax.swing.JButton SEARCHButtonEmployee;
    private javax.swing.JButton SEARCHButtonReservation;
    private javax.swing.JButton SearchButtonFlight;
    private javax.swing.JTextField SearchFlightText;
    private javax.swing.JTable flightTable;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel msgLabel;
    private javax.swing.JComboBox searchCombo;
    // End of variables declaration//GEN-END:variables
}
